<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>应用Vue的watch方法</title>
<!--引入Vue库-->
<script src="vue.js"></script>
</head>
<body>    
<div id="app">
    <button @click="x++">x加1</button>
    <p>{{ message }}</p>
</div>
<script>
var vm = new Vue({
  el: '#app',
  data: {
    x: 1,
    message:''
  },
  watch: {
    x: function (newVal, oldVal) {
      this.message = 'x的原值为' + oldVal + '，x的新值为' + newVal;
    }
  }
})
</script>
</body>
</html>